package servlet;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Employee;
import service.EmployeeService;
import serviceImpl.EmployeeServiceImpl;

/**
 * 
 */
public class EmployeeAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	EmployeeService employeeService=new EmployeeServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String empName = request.getParameter("empName");
		String email = request.getParameter("email");
		String phone = request.getParameter("phone");
		String deptId = request.getParameter("deptId");
		String gender = request.getParameter("gender");
		String hireDate = request.getParameter("hireDate");
		
		Employee employee=new Employee();
		
		employee.setEmpName(empName);
		employee.setEmail(email);
		employee.setPhone(phone);
		employee.setDeptId(Integer.parseInt(deptId));
		employee.setGender(gender);
		
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
		Date date=new Date();
		try {
			date = sdf.parse(hireDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		employee.setHireDate(date);
				
		employeeService.addEmployee(employee);
		
		request.getRequestDispatcher("/EmployeeListJumpServlet").forward(request, response);
		

	}

}
